POSITIONPRICE

Category: ProBacktest

Definition: POSITIONPRICE is a function in ProBuilder language that calculates the average price of all currently open positions. This function is particularly useful for traders who need to track the average entry price of multiple trades to manage their positions effectively.

Syntax:

PositionPrice

You can also access the average position price from previous periods by using an index offset. For example, PositionPrice[1] retrieves the average position price from the previous candle.

Example Usage:

Consider a scenario where you want to calculate the floating profit of all open positions and implement a simple trading strategy that averages down based on specific conditions:

// Calculate floating profit
floatingprofit = (((close - positionprice) * pointvalue) * countofposition) / pipsize

// Define MACD indicator
myMACD = MACD[12,26,9](close)

// Entry condition
long = myMACD crosses over 0
IF NOT LongOnMarket AND long THEN
    BUY 1 CONTRACT AT MARKET
ENDIF

// Averaging down condition
IF TRADEINDEX(1) > 5 AND TRADEPRICE(1) - Close > 20 AND LongOnMarket THEN
    BUY 1 CONTRACT AT MARKET
ENDIF

// Exit condition
IF COUNTOFPOSITION >= 2 AND Close > POSITIONPRICE THEN
    SELL AT MARKET
ENDIF

// Set a target profit
SET TARGET PROFIT 20

Explanation:

  • The floatingprofit variable calculates the current unrealized profit or loss of all open positions.
  • The script uses the MACD technical indicator to determine entry points for buying contracts.
  • The ‘averaging down’ strategy is implemented by buying additional contracts if the conditions specified are met (e.g., the trade index is greater than 5 and the price has moved significantly from the last trade price).
  • Positions are closed when the current closing price is higher than the average position price, assuming there are at least two open positions.
  • A target profit is set to manage the trade exit strategy effectively.

This example demonstrates how to use POSITIONPRICE in a trading strategy to manage entries, averaging down, and exits based on the average price of open positions.

Related Instructions:

  • TRADEPRICE probacktest
  • Logo Logo
    Loading...